<template>
  <div class="nav-header">
    <i @click="menuFoldAction">
      <el-icon v-if="isFold"><Expand /></el-icon>
      <el-icon v-else><Fold /></el-icon>
    </i>
    <!-- breadcrumb -->
    <bread-crumb :breadCrumbInfo="breadCrumbInfo"></bread-crumb>
  </div>
</template>
<script lang="ts">
import BreadCrumb from '@/common-ui/braadcrumb/src/BreadCrumb.vue'
import { defineComponent, ref, computed } from 'vue'
import { useRoute } from 'vue-router'
import { useStore } from '@/store'
import { breadCrumbMapToMenu } from '@/utils/map-menus'
export default defineComponent({
  components: { BreadCrumb },
  emits: ['changeMenuFold'],
  setup(props, { emit }) {
    const isFold = ref(true)
    const menuFoldAction = () => {
      emit('changeMenuFold', isFold.value)
      isFold.value = !isFold.value
    }
    const store = useStore()
    const breadCrumbInfo = computed(() => {
      const route = useRoute()
      const path = route.path
      return breadCrumbMapToMenu(store.state.login.userMenus, path)
    })
    return {
      menuFoldAction,
      isFold,
      breadCrumbInfo
    }
  }
})
</script>

<style scoped lang="less">
.nav-header {
  display: flex;
  width: 100%;
  height: 100%;
  padding: 0 20px;
  align-items: center;
  justify-content: space-evenly;
  .fold-menu {
    font-size: 30px;
    cursor: pointer;
  }
  .bread-crumb {
    flex: 1;
    text-align: left;
    margin-left: 10px;
  }
  .user-info {
    display: flex;
    justify-content: center;
    align-items: center;
    font-family: 'iconfont';
    .other-operate {
      font-size: 25px;
      margin-right: 10px;
      i {
        margin: 0 12px;
        user-select: none;
        cursor: pointer;
      }
    }
    .user-name {
      margin-left: 10px;
      margin-right: 10px;
      font-size: 15px;
      font-weight: 600;
    }
  }
}
</style>
